package w83b.w83bOperacionesPaso.w83bImpugnaciones;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import w83b.w83bBeans.W83bTipoDocumentoBean;

import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;

public class W83bCargaTiposDocumentoOutOP extends Q70ActionPasoOP{

	
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
	}

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		JSONObject resultado = new JSONObject ();
		JSONArray listaTipos = new JSONArray();
		
		List listaTiposContexto=(ArrayList)contexto.get("w83bListResultado");
		W83bTipoDocumentoBean tipodocBean=null;
		JSONObject tipoDocJson=null;
		for (int i=0;i<listaTiposContexto.size();i++)
		{
			tipoDocJson=new JSONObject();//NOPMD
			tipodocBean=(W83bTipoDocumentoBean)listaTiposContexto.get(i);
			tipoDocJson.put("idTipoDoc", tipodocBean.getIdTipoDocumento()+"_"+i);
			tipoDocJson.put("desc", tipodocBean.getDescripcion());
			tipoDocJson.put("descFase", tipodocBean.getDescripcionFase());
			tipoDocJson.put("descTramite", tipodocBean.getDescripcionTramite());
			listaTipos.put(tipoDocJson);
	
		}
		resultado.put("listaTipos", listaTipos);
		resultado.put("resultado", "ok");
		response.setContentType("text/javascript;charset=iso-8859-1");
		response.setHeader("Pragma", "cache");
		response.setHeader("Expires", "0");
		response.setHeader("Cache-Control", "private");
		response.setStatus(HttpServletResponse.SC_OK);
		PrintWriter out = response.getWriter();
		out.print(resultado.toString());
		out.flush();
		
		return null;
		
	}
}
